﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace DirectSell.Common.Attributes
{
    /// <summary>
    /// 版本号验证类--郭文昊
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class VersionAttribute : ValidationAttribute
    {

        /// <summary>
        /// 构造函数
        /// </summary>       
        /// <param name="errorMessage">错误提示信息</param>
        public VersionAttribute(string errorMessage) : base(errorMessage)
        {

        }
        /// <summary>
        /// 验证方法--郭文昊
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(object value)
        {
            var versionKey = HttpContext.Current.Request.Url.AbsolutePath.Replace("/", "").Trim().ToUpper();
            var val = value as string;
            return AppSettingsData.VersionList[versionKey].Contains(val.ToUpper());
        }
    }
    public class AppSettingsData
    {
        [Description("版本键值集合")]
        public static IDictionary<string, string[]> VersionList { get; set; }
        
    }

         
}
